#!/user/bin/env python3
# -*- coding: utf-8 -*-
from pymysql import Connection

# 获取到数据库对象
conn = Connection(
    host="localhost",  # 主机名(ip地址)
    port=3306,  # 端口号：默认3306
    user='root',  # 账户名
    password='123456'  # 密码
)
# 打印mysql数据库的软件信息
# print(conn.get_host_info())
# print(conn.get_server_info())

# 获取游标对象,选择数据库
cursor = conn.cursor()
conn.select_db("yiqing")
# 使用游标对象执行sql语句
# cursor.execute("create table test_pymysql(id int);")
cursor.execute("select * from yiqing.student;")
result: tuple = cursor.fetchall()  # 查询的结果是元组对象
for r in result:
    print(r)
# 关闭数据库的连接
conn.close()
